package com.example;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.crypto.digest.MD5;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;

/**
 * @author csp 2022-11-24
 */
public class JinYunHttpTest {

    static String secret = "";

    private static void getSecret() {

        String appKey = "A331122465898202112014795";
        String timestamp = System.currentTimeMillis() + "";
        String secret = "f850f6c050ce4fb19586971afcfb657a";
        String sign = MD5.create().digestHex(appKey + secret + timestamp);
        Map<String, Object> map = MapUtil.<String, Object>builder()
                .put("appKey", appKey)
                .put("sign", sign).put("requestTime", timestamp).build();
        String post = HttpUtil.post("https://interface.zjzwfw.gov.cn/gateway/app/refreshTokenByKey.htm", map);

        JinYunHttpTest.secret = Optional.ofNullable(post)
                .map(JSON::parseObject)
                .map(e -> e.getJSONObject("datas"))
                .map(e -> e.getString("requestSecret")).orElse("");


    }

    private static Map<String, Object> getSign() {
        String appKey = "A331122465898202112014795";
        String timestamp = System.currentTimeMillis() + "";
        String sign = MD5.create().digestHex(appKey + secret + timestamp);
        return MapUtil.<String, Object>builder()
                .put("appKey", appKey)
                .put("sign", sign).put("requestTime", timestamp).build();
    }

    public static void main(String[] args) {
        for (int i = 0; i < 300; i++) {
            getSecret();
            for (int j = 0; j < 50; j++) {
                CompletableFuture<Void> f1 = CompletableFuture.runAsync(() -> 低保接口());
                CompletableFuture<Void> f2 = CompletableFuture.runAsync(() -> 特困在册家庭信息查询());
                CompletableFuture<Void> f3 = CompletableFuture.runAsync(() -> 行程核验信息服务());
                CompletableFuture<Void> f4 = CompletableFuture.runAsync(() -> 行程核验查询短信验证服务());
                CompletableFuture<Void> f5 = CompletableFuture.runAsync(() -> 新冠病毒疫苗接种信息());
                CompletableFuture<Void> f6 = CompletableFuture.runAsync(() -> 核酸检测数据查询());
                CompletableFuture<Void> f7 = CompletableFuture.runAsync(() -> 全省健康码基本信息查询());
                CompletableFuture<Void> f8 = CompletableFuture.runAsync(() -> 质量信用平台_失信企业黑名单());
                CompletableFuture<Void> f9 = CompletableFuture.runAsync(() -> 省残联中华人民共和国残疾人证());
                CompletableFuture<Void> f10 = CompletableFuture.runAsync(() -> 单位未履行生效裁判信息查询());
                CompletableFuture<Void> f11 = CompletableFuture.runAsync(() -> 严重违法失信企业名单信息());
                CompletableFuture<Void> f12 = CompletableFuture.runAsync(() -> 省工商局营业执照());
                CompletableFuture.allOf(f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12).join();
            }
        }
    }
    public static void 低保接口() {
        Map<String, Object> map = getSign();
        map.put("mhz", "吴秋根");
        map.put("mhzsfz", "330621196908214796");

        String post = HttpUtil.post("https://interface.zjzwfw.gov.cn/gateway/api/001003010/dataSharing/mztHjBizDbZcmain.htm", map);
        System.out.println(post);

    }


    public static void 特困在册家庭信息查询() {
        Map<String, Object> map = getSign();
        map.put("mhz", "吕泉生");
        map.put("mhzsfz", "330724195403015214");

        String post = HttpUtil.post("https://interface.zjzwfw.gov.cn/gateway/api/001003010/dataSharing/mztHjBizTkZcmain.htm", map);
        System.out.println(post);

    }

    public static void 行程核验信息服务() {
        Map<String, Object> map = getSign();
        map.put("phone", "17788599608");
        map.put("queryId", RandomUtil.randomUUID());
        map.put("city", "0");

        String post = HttpUtil.post("https://interface.zjzwfw.gov.cn/gateway/api/001003001/dataSharing/OwQ79dcpSaDW050b.htm", map);
        System.out.println(post);

    }

    public static void 行程核验查询短信验证服务() {
        Map<String, Object> map = getSign();
        map.put("phone", "吴秋根");
        map.put("queryId", "330621196908214796");
        map.put("secert", "330621196908214796");
        map.put("sendTime", DateUtil.now());

        String post = HttpUtil.post("https://interface.zjzwfw.gov.cn/gateway/api/001003001/national/deYxdfMgX8cd8h76.htm", map);
        System.out.println(post);

    }

    public static void 新冠病毒疫苗接种信息() {
        Map<String, Object> map = getSign();
        map.put("xm", "朱晓凌");
        map.put("zjhm", "654001197804050322");

        String post = HttpUtil.post("https://interface.zjzwfw.gov.cn/gateway/api/010010010010012/dataSharing/09TaLf9e4znkff30.htm", map);
        System.out.println(post);

    }

    public static void 核酸检测数据查询() {
        Map<String, Object> map = getSign();
        map.put("idcardNo", "330521199411170212");
        String post = HttpUtil.post("https://interface.zjzwfw.gov.cn/gateway/api/001003001/dataSharing/8fGO7c2lb5S13Q0a.htm", map);
        System.out.println(post);

    }

    public static void 全省健康码基本信息查询() {
        Map<String, Object> map = getSign();
        map.put("sfzh", "422802197009181740");

        String post = HttpUtil.post("https://interface.zjzwfw.gov.cn/gateway/api/001003001/dataSharing/uU4lb0350783d2fa.htm", map);
        System.out.println(post);

    }

    public static void 质量信用平台_失信企业黑名单() {
        Map<String, Object> map = getSign();
        map.put("FRMC", "嘉兴市南湖区余新镇欧野电器厂");

        String post = HttpUtil.post("https://interface.zjzwfw.gov.cn/gateway/api/001003035/dataSharing/867505UwUDfaipf3.htm", map);
        System.out.println(post);

    }

    public static void 省残联中华人民共和国残疾人证() {
        Map<String, Object> map = getSign();
        map.put("name", "何天鹏");
        map.put("identitycard", "620422198409223712");

        String post = HttpUtil.post("https://interface.zjzwfw.gov.cn/gateway/api/001003061/certificate/1ea9w4ezQVcvQ889.htm", map);
        System.out.println(post);

    }

    public static void 单位未履行生效裁判信息查询() {
        Map<String, Object> map = getSign();
        map.put("gymc", "杭州星神文化传播有限公司");
        map.put("tyshxydm", "91330108MA27YAGCX0");

        String post = HttpUtil.post("https://interface.zjzwfw.gov.cn/gateway/api/001021001/dataSharing/sfyHjDwwlxsxcpxx.htm", map);
        System.out.println(post);

    }

    public static void 严重违法失信企业名单信息() {
        Map<String, Object> map = getSign();
        map.put("uniscid", "91330683MA29D92C5X");

        String post = HttpUtil.post("https://interface.zjzwfw.gov.cn/gateway/api/001003033/dataSharing/VjV1fdce6emYEe8f.htm", map);
        System.out.println(post);

    }

    public static void 省工商局营业执照() {
        Map<String, Object> map = getSign();
        map.put("uniscid", "91230523MA1C690L9R");
        String post = HttpUtil.post("https://interface.zjzwfw.gov.cn/gateway/api/001003001029/dataSharing/Y3beUxl9Sxa0e7ab.htm", map);
        System.out.println(post);

    }

}
